/**
 * Created by developer on 17-2-22.
 */
var $id;
var $status;
var $rightSlider = $(".aside-slider-content");
var $arr = ["size", "download_size"];
var $cover = $(".masking");
$(function () {
    var editPropertyIndex = null;
    //新增商品适用年龄
    $(".add-product-apply-age").on("click", function () {
        $(".container-product-apply-age").children(".panel_header").html("新增商品适用年龄<span class='glyphicon glyphicon-remove cancel'></span>");
        modifyDisplayBlock($(".container-product-apply-age"));
        //关闭弹出框
        $(".container-product-apply-age").find(".cancel").on("click", function () {
            modifyDisplayNone($(".container-product-apply-age"));
        });
        //"保存并添加下一个"按钮显示
        $("#save_add_next").show();
    });
    //列表点击事件，出现侧栏
    $(".list-item").on("click", function () {
        // console.log($(this).attr("id"));
        var $currentId = $(this).attr("id");
        // expandOrCloseSidebar(getStatus($currentId), $currentId);
        console.log($rightSlider.css("right"));
        if ($rightSlider.css("right") == "-400px") {
            $rightSlider.animate({
                right: "0px"
            });
        } else {
            $rightSlider.animate({
                right: "-400px"
            });
        }
    });
    //关闭侧栏
    $rightSlider.find(".cancel").on("click", function () {
        $rightSlider.animate({right: "-400px"});
        $status = "close";
    });
    //编辑自定义年龄段
    $("#edit_product_apply_age").on("click", function () {
        $(".container-product-apply-age").children(".panel_header").html("修改商品适用年龄<span class='glyphicon glyphicon-remove cancel'></span>");
        modifyDisplayBlock($(".container-product-apply-age"));
        //关闭弹出框
        $(".container-product-brand").find(".cancel").on("click", function () {
            modifyDisplayNone($(".container-product-apply-age"));
        });
        //"保存并添加下一个"按钮隐藏
        $("#save_add_next").hide();
    });
    //删除自定义年龄段
    $("#delete_product_apply_age").on("click", function () {
       modifyDisplayBlock($(".container-delete-product-apply-age"));
    });
    //关闭删除框
    $(".container-delete-product-apply-age").find(".cancel").on("click", function () {
        modifyDisplayNone($(".container-delete-product-apply-age"));
    });

    //年龄段
    $(".generation-slider").jRange({
        width: 390,
        from: 15,
        to: 80,
        step: 1,
        scale: [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80],
        format: "%s",
        showLabels: true,
        snap: true
    });
});

//获取页面侧栏的打开或关闭的状态
function getStatus(currentId) {
    if ($id == currentId) {
        $status = "close";
        $id = "";
    } else {
        $status = "open";
        $id = currentId;
    }
    console.log($id);
    return $status;
}
//通过id对比打开或关闭页面侧栏
function expandOrCloseSidebar($status, currentId) {
    if ($status == "close") {
        $rightSlider.animate({right: "-400px"});
    } else if($status == "open") {
        for (var i = 0; i < $arr.length; i++) {
            if ($arr[i] == currentId) {
                $rightSlider.animate({right: "0px"});
            } else {
                console.log("没有对应的年龄段");
            }
        }
    }
}
//修改css样式display为block
function modifyDisplayBlock(obj) {
    obj.css("display", "block");
    $cover.css("display", "block");
}
//修改css样式display为none
function modifyDisplayNone(obj) {
    obj.css("display", "none");
    $cover.css("display", "none");
}